package com.whq.knowverywell.business;

import android.content.Context;

import com.whq.knowverywell.business.db.TblConfHandler;
import com.whq.knowverywell.util.StringUtil;

public class LoginUtil {
//	private static final String TAG = "LoginUtil";

	/**
	 * 是否已经登录
	 * @param context
	 * @return
	 */
	public static boolean chkLogin(Context context) {
		if (context == null) {
			return false;
		}
		TblConfHandler tblConfHandler = new TblConfHandler(context);
		String loginToken = tblConfHandler.getOneConf(TblConfHandler.KEY_LOGIN_TOKEN);
		if (StringUtil.isNotBlank(loginToken)) {
			return true;
		}
		return false;
	}

	/**
	 * 获取登录token
	 * @param context
	 * @return
	 */
	public static String getLoginToken(Context context) {
		if (context == null) {
			return "";
		}
		TblConfHandler tblConfHandler = new TblConfHandler(context);
		return tblConfHandler.getOneConf(TblConfHandler.KEY_LOGIN_TOKEN);
	}

	/**
	 * 获取登录用户公司编号
	 * @param context
	 * @return
	 */
	public static String getLoginGroupCode(Context context) {
		if (context == null) {
			return "";
		}
		TblConfHandler tblConfHandler = new TblConfHandler(context);
		return tblConfHandler.getOneConf(TblConfHandler.KEY_LOGIN_GROUP_CODE);
	}

	/**
	 * 获取登录用户的用户名
	 * @param context
	 * @return
	 */
	public static String getLoginUserName(Context context) {
		if (context == null) {
			return "";
		}
		TblConfHandler tblConfHandler = new TblConfHandler(context);
		return tblConfHandler.getOneConf(TblConfHandler.KEY_LOGIN_USER_NAME);
	}

	/**
	 * 清空登录信息
	 * @param context
	 */
	public static void clearLogin(Context context) {
		if (context == null) {
			return ;
		}
		TblConfHandler tblConfHandler = new TblConfHandler(context);
		tblConfHandler.saveOneConf(TblConfHandler.KEY_LOGIN_GROUP_CODE, "");
		tblConfHandler.saveOneConf(TblConfHandler.KEY_LOGIN_USER_NAME, 	"");
		tblConfHandler.saveOneConf(TblConfHandler.KEY_LOGIN_TOKEN, 		"");
	}
	
	
}
